package ar.com.photo_admin.taglibs

class ShoppingCartTagLib {
	
	def shoppingCartService
	def springSecurityService
	
	def manyPhotographersItems = { attrs, body ->		
		if (getPhotographersCount()>1) {			
			out << body()
		}
	}
	
	def oneOrManyPhotographersItems = { attrs, body ->
		if (getPhotographersCount()>0) {
			out << body()
		}
	}
	
	def noPhotographersItems = { attrs, body ->
		if (getPhotographersCount() == 0) {
			out << body()
		}
	}
	
	
	def getPhotographersCount(){
		return shoppingCartService.getPhotographersOwnerOfPhotosInCart().size()
	}
	
	def imageCart = { attrs, body ->
		out << """<img id="cartToolbarIcon" alt="" """
		if (shoppingCartService.hasPhotosInShoppingCart(springSecurityService.getCurrentUser())) {
			out << """src="${resource(dir:'images',file:'cart_filled_m.png')}" """
		}
		else {			
			out << """src="${resource(dir:'images',file:'cart_m.png')}" """
		}
		out << """ ></img> """
	}
}
